package com.szqhyxj.youxiangju.sys.util;

import android.text.TextUtils;

/**
 * Created by leung on 2018/11/3.
 */

public class PhonenumberUtil {
    public static boolean isMobileNO(String mobileNums) {
        /**
         * 判断字符串是否符合手机号码格式
         * 移动号段: 134,135,136,137,138,139,147,150,151,152,157,158,159,170,178,182,183,184,187,188
         * 联通号段: 130,131,132,145,155,156,170,171,175,176,185,186
         * 电信号段: 133,149,153,170,173,177,180,181,189
         * @param str
         * @return 待检测的字符串
         */
        String telRegex = "^1[345789]\\d{9}$";// "[1]"代表第1位为数字1，"[358]"代表第二位可以为3、5、8中的一个，"\\d{9}"代表后面是可以是0～9的数字，有9位。
        if (TextUtils.isEmpty(mobileNums))
            return false;
        else
            return mobileNums.matches(telRegex);
    }

    public static String hiddenBankCards(String bankCard) {
        char[] charArray = bankCard.toCharArray();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < charArray.length; i++) {
            if (i > charArray.length - 5) {
                sb.append(charArray[i]);
            } else {
                sb.append("*");
            }
        }
        return sb.toString();
    }

    public static String hiddenPhoneNumber(String str){
       String phone =  str.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2");
       return  phone;
    }
}
